package com.myqm.util.gateway;

import com.alibaba.fastjson.JSON; 

public class ConsumerGateway {

	static  String url = "http://222.196.35.4:8001";
	
	public static ConsumerInfo addConsumer(ConsumerInfo consumer) throws Exception {
		String path = url + "/consumers";
		consumer.setCustom_id("abc");
		consumer.setUsername("userabc");
		String result = "";
		System.out.println(path);
		result = ApiGatewayNetOp.netNotByGET(path, consumer, "POST");
		ConsumerInfo newConsumer = JSON.parseObject(result, ConsumerInfo.class);
		System.out.println(newConsumer);
		return consumer;
	}
	
	public static ConsumerInfo getConsumer(String nameOrId) throws Exception {
		String path = url + "/consumers";
		if(nameOrId != null) {
			path += "/" + nameOrId;
		}
		String result = "";
		System.out.println(path);
		result = ApiGatewayNetOp.netByGET(path, null);
		ConsumerInfo consumer = JSON.parseObject(result, ConsumerInfo.class);
		System.out.println(result);
		return consumer;
	}
	
	public static ConsumerList getConsumers() throws Exception {
		String path = url + "/consumers";
		String result = ""; 
		System.out.println(path);
		result = ApiGatewayNetOp.netByGET(path, null);
		ConsumerList consumers = JSON.parseObject(result, ConsumerList.class);
		System.out.println(consumers);
		return consumers;
	}
	
	public static ConsumerInfo delConsumer(String nameOrId) throws Exception {
		String path = url + "/consumers";
		if(nameOrId != null) {
			path += "/" + nameOrId;
		}
		String result = "";
		System.out.println(path);
		result = ApiGatewayNetOp.netNotByGET(path, null, "DELETE");
		ConsumerInfo consumer = JSON.parseObject(result, ConsumerInfo.class);
		System.out.println(consumer);
		return consumer;
	}
	
	public static void main(String[] args) {
		try {
			//ConsumerGateway.addConsumer(new ConsumerInfo());
			ConsumerGateway.getConsumers();
			//ConsumerGateway.delConsumer("userabc");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
